import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Random;

public class MenuFrame extends Frame {

	/**
	 * 
	 */
	private final Color colors[] = {Color.BLACK,Color.DARK_GRAY, Color.GRAY, Color.LIGHT_GRAY, Color.RED, Color.ORANGE,
			Color.MAGENTA, Color.PINK, Color.GREEN, Color.YELLOW, Color.BLUE, Color.CYAN}	;
	private final String colNames[] = {"Black", "Dark Gray" , "Gray", "Light Gray", "Red", "Orange", "Magenta", "Pink", "Green","Yellow", "Blue", "Cyan"};
	private static final long serialVersionUID = 4156494860703412270L;
	private MyCanvas can;
	private Checkbox sqr;
	private Checkbox f;
	private Checkbox cir;
	private boolean w= true; 
	private boolean fill = false;
	private Choice col;
	private Color cc = Color.BLACK;

	MenuFrame(MyCanvas c){
		super("Menu");
		can = c;
		setLocation(240,200);
		setSize(50, 220);
		setResizable(true);
		setLayout(new BorderLayout());
		
		Button clear = new Button("Clear");
		Button exit = new Button("Exit");
		Button draw = new Button("Draw");

		Panel boxes = new Panel();
		Panel buttons = new Panel();
		
		sqr = new Checkbox("Square");
		sqr.setState(true);
		cir = new Checkbox("Circle");
		f = new Checkbox("Filled");
		
		col = new Choice();
		for (int i = 0; i<colNames.length; i++)
			col.addItem(colNames[i]);
		
		boxes.setLayout(new GridLayout(4,1));
		boxes.add(f);
		boxes.add(sqr);
		boxes.add(cir);
		boxes.add(col);
		
		buttons.setLayout(new GridLayout(1,2));
		buttons.add(clear);
		buttons.add(exit);
		
		col.addItemListener(new ItemListener(){
			public void itemStateChanged(ItemEvent e) {
				for(int i = 0 ; i< colNames.length; i++)
					if (colNames[i].equals(e.getItem().toString()))
						cc = colors[i];
				
				System.out.println(cc);
						
			}
		});	
		f.addItemListener(new ItemListener(){
			public void itemStateChanged(ItemEvent e) {
				fill = f.getState();
			}
		});	
		
		sqr.addItemListener(new ItemListener(){
			public void itemStateChanged(ItemEvent e) {
				w = sqr.getState();
				cir.setState(!sqr.getState());
			}
		});	
		
		cir.addItemListener(new ItemListener(){
			public void itemStateChanged(ItemEvent e) {
				w = !cir.getState();
				sqr.setState(!cir.getState());
			}
		});
		exit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}

		});
		clear.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				can.clear();
			}

		});
		draw.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Random ra = new Random();
				if(w){
					if (fill)
						can.fillSquare(ra.nextInt(can.getWidth()/2), ra.nextInt(can.getHeight()/2), ra.nextInt(can.getHeight()), cc);
					else
						can.drawSquare(ra.nextInt(can.getWidth()/2), ra.nextInt(can.getHeight()/2), ra.nextInt(can.getHeight()), cc);
				}
				else{
					if (fill)
						can.fillCircle(ra.nextInt(can.getWidth()/2), ra.nextInt(can.getHeight()/2), ra.nextInt(can.getHeight()), cc);
					else
						can.drawCircle(ra.nextInt(can.getWidth()/2), ra.nextInt(can.getHeight()/2), ra.nextInt(can.getHeight()), cc);
				}	
			}		

		});

		add(boxes, BorderLayout.NORTH);
		add(buttons, BorderLayout.SOUTH);
		add(draw, BorderLayout.CENTER);

		setVisible(true);
	}





}
